﻿//
// $HeadURL: http://codeka-memcache.googlecode.com/svn/trunk/Benchmark/ExecuteBenchmark.cs $
// $Revision: 12 $
// $Author: dean.codeka $     $Date: 2010-02-22 10:54:11 +0000 (Mon, 22 Feb 2010) $
//
// Copyright © 2009-2010 Dean Harding, all rights reserved.
//

using System;
using System.Diagnostics;

namespace Benchmark
{
    /// <summary>
    /// This class actually runs the benchmark. We use the same
    /// logic for all benchmarks, to try and keep the differences
    /// to a minimum.
    /// </summary>
    static class ExecuteBenchmark
    {
        public static void Execute<TClientWrapper>()
            where TClientWrapper : IClientWrapper, new()
        {
            // todo: flush the cache first

            // add a bunch of values initially to the cache
            var timer = Stopwatch.StartNew();
            var cw = new TClientWrapper();
            for(int i = 0; i < 10000; i++)
            {
                cw.Set(string.Format("initial-{0}", i), GetValue());
            }
            timer.Stop();
            Console.WriteLine("10,000 objects added in {0:#,##0}ms", timer.ElapsedMilliseconds);
        }

        private static object GetValue()
        {
            return "hello-world";
        }
    }
}
